// pages/hot/index.js
const {
  get
} = getApp();
Page({
  data: {
    params: {
      page: 1,
      pageSize: 20
    },
    showLoading: true,
    showPage:false,
    dataList: []
  },
  // 初始化加载
  onLoad: function () {
    this.getList();
  },
  // 获取数据
  getList() {
    if (this.data.showLoading) {
      get("/index/hot", this.data.params).then(res => {
        if (res.result == 1) {
          this.setData({
            dataList: this.data.dataList.concat(res.data),
            showPage:true
          });
          if (res.data.length < this.data.params.pageSize) {
            this.setData({
              showLoading: false
            })
          }
        }
      })
    }
  },
  //  页面上拉触底事件的处理函数
  onReachBottom: function () {
    this.setData({
      "params.page": this.data.params.page += 1
    });
    this.getList();
  },
  // 详情页跳转
  goToCommodity: function (e) {
    wx.navigateTo({
      url: `../commodity/index?unique_id=${e.currentTarget.dataset.unique_id}`,
    })
  },
  onShow: function () {
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    });
  }
})